// ChildView.cpp : implementation of the CChildView class
//

#include "stdafx.h"
#include "Tester.h"
#include "ChildView.h"
#include <cmath>

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

enum Electordes {A1,FP1,F3,F7,C3,T3,P3,T5,O1,A2,FP2,F4,F8,C4,T4,P4,T6,O2,FZ,CZ,PZ,OZ};
enum Regions {Left=1,Right=2,LeftF=4,RightF=8,Center=16,Vertex=32,LeftO=64,RightO=128};


// CChildView
#define PI 3.1415926535897932384626
#define F(x) (2+sin(2*PI*10*(x))+3.3*sin(2*PI*80*(x)))
CChildView::CChildView()
{

}

CChildView::~CChildView()
{
}


BEGIN_MESSAGE_MAP(CChildView, CWnd)
	ON_WM_PAINT()
	ON_WM_SIZE()
	ON_WM_CREATE()
END_MESSAGE_MAP()



// CChildView message handlers

BOOL CChildView::PreCreateWindow(CREATESTRUCT& cs) 
{
	if (!CWnd::PreCreateWindow(cs))
		return FALSE;

	cs.dwExStyle |= WS_EX_CLIENTEDGE;
	cs.style &= ~WS_BORDER;
	cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS, 
		::LoadCursor(NULL, IDC_ARROW), reinterpret_cast<HBRUSH>(COLOR_WINDOW+1), NULL);



	return TRUE;
}

void CChildView::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here
	
	// Do not call CWnd::OnPaint() for painting messages
}


void CChildView::OnSize(UINT nType, int cx, int cy)
{
	CWnd::OnSize(nType, cx, cy);

	// TODO: Add your message handler code here
	
	RECT cR;
	this->GetClientRect(&cR);
	ax.SetWindowPos(0,0,0,cR.right,cR.bottom,SWP_NOZORDER);
}

int CChildView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CWnd::OnCreate(lpCreateStruct) == -1)
		return -1;

	// TODO:  Add your specialized creation code here
	srand(time(0));
		RECT cR;
	//this->GetClientRect(&cR);
	memset(&cR,0,sizeof(RECT));
	ax.Create(0,0,WS_CHILD,cR,this,454);
	ax.ShowWindow(SW_SHOW);
	ax.InitAx();
	ax.SetSamplingRate(1000);

	
	ax.AddChannel(O1);
	//ax.SetChannelName(L"ch0");
	for(double i=0;i<120.00001;i+=0.001)//sampling rate=1000
		ax.AddData(F(i));
	ax.EndChannel();
	ax.AddChannel(O2);
	//ax.SetChannelName(L"ch1");
	for(double i=0;i<120.00001;i+=0.001)//sampling rate=1000
		ax.AddData(2*F(i)+rand()/(double)RAND_MAX*32.2);
	ax.EndChannel();
	ax.SetMode(2);
	if(ax.StartCalc()==0)
		AfxMessageBox(L"error!");
	ax.DrawToFile(L"test.bmp",0,1,800,600);

	return 0;
}
